﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using QiAdmin.Core;
using QiAdmin.Core.Attributes;
using QiAdmin.Core.Models;
using QiAdmin.Model.Dtos.Input;
using QiAdmin.Service.IService;
using QiAdmin.Service.Service;

namespace QiAdmin.WebApi.Controllers.System
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SysTaskController : ControllerBase
    {
        readonly ITSysTaskService _tSysTaskService;
        readonly ITSysTaskLogService _tSysTaskLogService;
        public SysTaskController(ITSysTaskService tSysTaskService, ITSysTaskLogService tSysTaskLogService)
        {
            _tSysTaskService = tSysTaskService;
            _tSysTaskLogService = tSysTaskLogService;
        }

        [Permission(PermissionType.Query)]
        [HttpPost]
        public ApiJsonResult GetPageList(TSysTask_IN input)
        {
            var res = _tSysTaskService.GetPageList(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.Add)]
        [HttpPost]
        public ApiJsonResult Add(TSysTask_IN input)
        {
            var res = _tSysTaskService.Add(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.Edit)]
        [HttpPost]
        public ApiJsonResult Edit(TSysTask_IN input)
        {
            var res = _tSysTaskService.Edit(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.Query)]
        [HttpPost]
        public ApiJsonResult Get(TSysTask_IN input)
        {
            var res = _tSysTaskService.Get(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.Delete)]
        [HttpPost]
        public ApiJsonResult RemoveRange(List<TSysTask_IN> input)
        {
            var res = _tSysTaskService.RemoveRange(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.Query)]
        [HttpPost]
        public ApiJsonResult GetTaskLogs(TSysTaskLog_IN input)
        {
            var res = _tSysTaskLogService.GetPageList(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.System)]
        [HttpPost]
        public ApiJsonResult RunTask(TSysTask_IN input)
        {
            var res = _tSysTaskService.RunTask(input);
            return ApiJsonResult.Convert(res);
        }
    }
}
